package _15_generics._15_8;

/**
 * 使用工厂对象创建对象
 * 工厂对象就是Class对象
 * 直接使用class.newInstance
 */
public class _02_InstantiateGenericType {
    public static void main(String[] args) {
        ClassAsFactory<Employee> f1 = new ClassAsFactory(Employee.class);
        System.out.println(f1.getClass());
        //Integer 没有默认构造器
        ClassAsFactory<Integer> f2 = new ClassAsFactory(Integer.class);
        System.out.println(f2.getClass());
    }
}

class Employee{}

class ClassAsFactory<T>{
    T obj;
    public ClassAsFactory(Class<T> kind){
        try {
           obj = kind.newInstance();
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }
}
